package com.byzk.invoice.xml.Doc_0.Annots.Page_0;

import com.byzk.invoice.util.DocumentUtil;
import org.dom4j.*;

import java.io.File;

/**
 * 创建Annotation.xml.
 *
 * @author 康鹏 2020-05-21
 */
public class Annotation {

    /**
     * 创建Doc_0/Annots/Page_0/Annotation.xml.
     * @param annotationXmlPath Annotation.xml存放路径
     * @throws Exception Exception
     */
    public static void createAnnotationXml(String annotationXmlPath) throws Exception {

        Namespace namespace = new Namespace("ofd", "http://www.ofdspec.org/2016");
        //创建外层<ofd:PageAnnot />
        Element rootElt = DocumentHelper.createElement(new QName("PageAnnot", namespace));
        //创建<ofd:Annot />
        Element annotElt = rootElt.addElement("ofd:Annot");
        annotElt.addAttribute("Type", "Stamp");
        annotElt.addAttribute("ID", "117");
        annotElt.addAttribute("Subtype", "SignatureInFile");
        //创建<Parameters />
        Element parametersElt = annotElt.addElement("Parameters");
        Element parameterElt = parametersElt.addElement("Parameter");
        parameterElt.addAttribute("Name", "fp.NativeSign");
        parameterElt.setText("original_invoice");
        //创建<ofd:Appearance />
        Element appearanceElt = annotElt.addElement("ofd:Appearance");
        appearanceElt.addAttribute("Boundary", "4.5 104 115 20");

        Document document = DocumentHelper.createDocument(rootElt);
        DocumentUtil.writer(document, annotationXmlPath + File.separator + "Doc_0" + File.separator + "Annots"
                + File.separator + "Page_0" + File.separator + "Annotation.xml", true);
    }

}
